import {Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';

@Injectable({
    providedIn: 'root'
})
export class HelpcenterserviceService {

    constructor(
        private http: HttpClient
    ) {
    }

    helpCenterCommonRequest(url: string, data?: any, method?: string): any {
        switch (method) {
            case 'post' :
            case 'POST' :
                // 语句
                return new Promise((resolve, reject) => {
                    this.http.post(url, data).toPromise().then(res => {
                        resolve(res);
                    }, error => {
                        reject(false);
                    });
                });
                break; // 可选
            case 'get' :
            case 'GET' :
                // 语句
                return new Promise(((resolve, reject) => {
                    this.http.get(url).toPromise().then(res => {
                        resolve(res);
                    }, error => {
                        reject(false);
                    });
                }));
                break; // 可选
            // 你可以有任意数量的case语句
            default : // 可选
                // 语句
                return new Promise((resolve, reject) => {
                    this.http.post(url, data).toPromise().then(res => {
                        resolve(res);
                    }, error => {
                        reject(false);
                    });
                });
        }
    }

}
